<!--
 * @Author: your name
 * @Date: 2021-11-16 18:48:14
 * @LastEditTime: 2021-11-18 16:35:45
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue_cli_demo5\src\components\ComponentAside.vue
-->
 <template slot="title">
    <el-menu  
    class="el-menu-vertical-demo" 
    :collapse="isCollapse"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    >
    <h3 v-show="!isCollapse">通用后台管理系统</h3>
    <h3 v-show="isCollapse">后台</h3>

    <!-- 主菜单 -->
    <el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path">
      <i :class="'el-icon-'+ item.icon"></i>
      <span slot="title">{{item.label}}</span>
    </el-menu-item>
    <!-- 带子菜单 -->
    <el-submenu :index="item.label" v-for="item in hasChildren" :key="item.label">
      <template slot="title">
        <i :class="'el-icon-'+ item.icon"></i>
        <span slot="title">{{item.label}}</span>
      </template>
      <!-- 二级菜单 -->
      <el-menu-item-group v-for="(subItem,subIndex) in item.children" :key="subIndex">
        
        <el-menu-item :index="subItem.path">
          <i :class="'el-icon-'+ subItem.icon"></i>
          {{subItem.label}}</el-menu-item>
      </el-menu-item-group>
      
    </el-submenu>
    
    <div>{{listtest}}</div>
   
  </el-menu>
</template>


<style lang="scss" scoped>
.el-menu {
  height: 1000px;
  border: none;
  h3 {
    color: #ffffff;
    text-align: center;
    line-height: 48px;
  }
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 1000px;
}
</style>

<script>
import bus from '../assets/js/eventBus'
  export default {
    props:['listtest'],
    data() {
      return {
        isCollapse: true,
        menu: [
        {
          path: "/",
          name: "home",
          label: "首页",
          icon: "s-home",
          url: "Home/Home",
        },
        {
          path: "/mall",
          name: "mall",
          label: "商品管理",
          icon: "video-play",
          url: "MallManage/MallManage",
        },
        {
          path: "/user",
          name: "user",
          label: "用户管理",
          icon: "user",
          url: "UserManage/UserManage",
        },
        {
          label: "其他",
          icon: "location",
          children: [
            {
              path: "/page1",
              name: "page1",
              label: "页面1",
              icon: "setting",
              url: "Other/PageOne",
            },
            {
              path: "/page2",
              name: "page2",
              label: "页面2",
              icon: "setting",
              url: "Other/PageTwo",
            },
          ],
        },
      ],
      };
    },
    methods: {
     
    },
    computed:{
      noChildren(){
        return this.menu.filter((item) => !item.children);
      },
      hasChildren(){
        return this.menu.filter((item) => item.children);
      }
    },
   mounted(){
      bus.$on("setIsCollapse",(msg)=>{
          console.log(msg)
          this.isCollapse = msg

      });//第二个参数是个回调函数，就是传过来的参数为msg,在将msg传给这个回调函数
    }

    
  }
</script>